package dmir.reaction.publico.graph.communities;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Communities {
	
	
	public static void main() {
		
	}
	
	
	public static Set<Community> readCommunities(String filename) throws IOException{
		
		Set<Community> communities = new HashSet<Community>();
		
		FileInputStream fstream = new FileInputStream(filename);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		
		while ((strLine = br.readLine()) != null) {	
			if (!strLine.startsWith("#") && strLine.length()>2) {
				
				Community c = new Community();
																
				String[] data = strLine.split(":");				
				String[] nodes = data[1].split("\\s");
				
				for (int i = 1; i < nodes.length; i++) {					
					c.addNode(Integer.parseInt(nodes[i].trim()));
				}				
				communities.add(c);				
			}
		}
		
		return communities;
	}
	
}
